package com.xz;

import org.junit.Test;

import java.util.HashMap;

/**
 * @author XZ
 * @create 2021-11-21 20:45
 */
public class Main {
    @Test
    public void testString(){
        String string = "jack";//3254239
        System.out.println(string.hashCode());
        int len = string.length();
        int hashcode = 0;
        for (int i = 0; i < len; i++) {
            char c = string.charAt(i);
//            hashcode = (hashcode<<5)-hashcode + c;
            hashcode = hashcode*31 + c;
        }
        System.out.println(hashcode);
    }

    @Test
    public void testHashCode() {
        Integer a = 110;
        Float b = 10.6f;
        Long c = 156l;
        Double d = 10.9;
        String e = "rose";
        System.out.println(a.hashCode());
        System.out.println(b.hashCode());
        System.out.println(c.hashCode());
        System.out.println(d.hashCode());
        System.out.println(e.hashCode());
    }

    @Test
    public void testPerson() {
        Person p1 = new Person(12, 175f, "jack");
        Person p2 = new Person(12, 175f, "jack");
        System.out.println(p1.hashCode());//直接生成的哈希值和内存地址有关
        System.out.println(p2.hashCode());

//        HashMap<Object, Object> map = new HashMap<>();
//        map.put(p1, "abc");
//        map.put(p2, "bcd");
//        System.out.println(map.size());

    }
}